home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / CWeb31p9b_locale.lha / CWeb / ctangle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-08  |  34.4 KB  |  1,743 lines

  1. /*1:*/
  2. #line 61 "ctangle.w"
  3.  
  4. /*2:*/
  5. #line 170 "ctangle.ch"
  6.  
  7. #include <string.h>
  8. #line 80 "ctangle.w"
  9.  
  10. /*:2*//*6:*/
  11. #line 185 "ctangle.ch"
  12.  
  13. #include <stdio.h>
  14.  
  15. #ifdef __TURBOC__
  16. #include <io.h>
  17. #endif
  18.  
  19. #ifndef _AMIGA
  20. typedef long int LONG;
  21. typedef unsigned char*STRPTR;
  22. #define EXEC_TYPES_H 1 
  23. #endif
  24.  
  25. #ifdef STRINGARRAY
  26. #undef STRINGARRAY 
  27. #endif
  28. #define get_string(n) AppStrings[n].as_Str
  29.  
  30. #include "bin/catalogs/cweb.h"
  31.  
  32. struct AppString
  33. {
  34. LONG as_ID;
  35. STRPTR as_Str;
  36. };
  37. extern struct AppString AppStrings[];
  38.  
  39. /*:6*//*62:*/
  40. #line 873 "ctangle.w"
  41.  
  42. #include <ctype.h> 
  43. #include <stdlib.h> 
  44.  
  45. /*:62*/
  46. #line 62 "ctangle.w"
  47.  
  48. #define banner get_string(MSG_BANNER_CT1)  \
  49.  
  50. #define max_bytes 90000 \
  51.  
  52. #define max_toks 270000
  53. #define max_names 4000 \
  54.  
  55. #define max_texts 2500
  56. #define hash_size 353
  57. #define longest_name 1000
  58. #define stack_size 50
  59. #define buf_size 100 \
  60.  
  61. #define ctangle 0
  62. #define cweave 1 \
  63.  
  64. #define and_and 04
  65. #define lt_lt 020
  66. #define gt_gt 021
  67. #define plus_plus 013
  68. #define minus_minus 01
  69. #define minus_gt 031
  70. #define not_eq 032
  71. #define lt_eq 034
  72. #define gt_eq 035
  73. #define eq_eq 036
  74. #define or_or 037
  75. #define dot_dot_dot 016
  76. #define colon_colon 06
  77. #define period_ast 026
  78. #define minus_gt_ast 027 \
  79.  
  80. #define xisalpha(c) (isalpha(c) &&((eight_bits) c<0200) ) 
  81. #define xisdigit(c) (isdigit(c) &&((eight_bits) c<0200) ) 
  82. #define xisspace(c) (isspace(c) &&((eight_bits) c<0200) ) 
  83. #define xislower(c) (islower(c) &&((eight_bits) c<0200) ) 
  84. #define xisupper(c) (isupper(c) &&((eight_bits) c<0200) ) 
  85. #define xisxdigit(c) (isxdigit(c) &&((eight_bits) c<0200) )  \
  86.  
  87. #define length(c) (size_t) ((c+1) ->byte_start-(c) ->byte_start) 
  88. #define print_id(c) term_write((c) ->byte_start,length((c) ) ) 
  89. #define llink link
  90. #define rlink dummy.Rlink
  91. #define root name_dir->rlink \
  92.  
  93. #define chunk_marker 0 \
  94.  
  95. #define spotless 0
  96. #define harmless_message 1
  97. #define error_message 2
  98. #define fatal_message 3
  99. #define mark_harmless {if(history==spotless) history= harmless_message;}
  100. #define mark_error history= error_message
  101. #define confusion(s) fatal(get_string(MSG_FATAL_CO66) ,s)  \
  102.  
  103. #define max_file_name_length 256
  104. #define cur_file file[include_depth]
  105. #define cur_file_name file_name[include_depth]
  106. #define web_file_name file_name[0]
  107. #define cur_line line[include_depth] \
  108.  
  109. #define show_banner flags['b']
  110. #define show_happiness flags['h']
  111. #define show_progress flags['p']
  112. #define use_amiga_keywords flags['a']
  113. #define use_german_macros flags['g']
  114. #define indent_param_decl flags['i']
  115. #define order_decl_stmt flags['o'] \
  116.  
  117. #define update_terminal fflush(stdout) 
  118. #define new_line putchar('\n') 
  119. #define putxchar putchar
  120. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  121. #define C_printf(c,a) fprintf(C_file,c,a) 
  122. #define C_putc(c) putc(c,C_file)  \
  123.  
  124. #define equiv equiv_or_xref \
  125.  
  126. #define section_flag max_texts \
  127.  
  128. #define string 02
  129. #define join 0177
  130. #define output_defs_flag (2*024000-1)  \
  131.  
  132. #define cur_end cur_state.end_field
  133. #define cur_byte cur_state.byte_field
  134. #define cur_name cur_state.name_field
  135. #define cur_repl cur_state.repl_field
  136. #define cur_section cur_state.section_field \
  137.  
  138. #define section_number 0201
  139. #define identifier 0202 \
  140.  
  141. #define normal 0
  142. #define num_or_id 1
  143. #define unbreakable 3
  144. #define verbatim 4 \
  145.  
  146. #define max_files 256
  147. #define translit_length 10 \
  148.  
  149. #define ignore 0
  150. #define ord 0302
  151. #define control_text 0303
  152. #define translit_code 0304
  153. #define output_defs_code 0305
  154. #define format_code 0306
  155. #define definition 0307
  156. #define begin_C 0310
  157. #define section_name 0311
  158. #define new_section 0312 \
  159.  
  160. #define constant 03 \
  161.  
  162. #define isxalpha(c) ((c) =='_') 
  163. #define ishigh(c) ((unsigned char) (c) >0177)  \
  164.  \
  165.  
  166. #define compress(c) if(loc++<=limit) return(c)  \
  167.  
  168. #define macro 0 \
  169.  
  170. #define app_repl(c) {if(tok_ptr==tok_mem_end) overflow(get_string(MSG_OVERFLOW_CT26) ) ;*tok_ptr++= c;} \
  171.  
  172.  
  173. #line 63 "ctangle.w"
  174.  
  175. /*5:*/
  176. #line 185 "ctangle.ch"
  177.  
  178. typedef short boolean;
  179. typedef unsigned char eight_bits;
  180. extern boolean program;
  181. extern int phase;
  182. #ifdef __TURBOC__
  183. #define HUGE huge
  184. #else
  185. #define HUGE
  186. #endif
  187.  
  188. /*:5*//*7:*/
  189. #line 185 "ctangle.ch"
  190.  
  191. char section_text[longest_name+1];
  192. char*section_text_end= section_text+longest_name;
  193. char*id_first;
  194. char*id_loc;
  195.  
  196. /*:7*//*8:*/
  197. #line 185 "ctangle.ch"
  198.  
  199. extern char buffer[];
  200. extern char*buffer_end;
  201. extern char*loc;
  202. extern char*limit;
  203.  
  204. /*:8*//*9:*/
  205. #line 185 "ctangle.ch"
  206.  
  207. typedef struct name_info{
  208. char HUGE*byte_start;
  209. struct name_info HUGE*link;
  210. union{
  211. struct name_info HUGE*Rlink;
  212.  
  213. char Ilk;
  214. }dummy;
  215. void HUGE*equiv_or_xref;
  216. }name_info;
  217. typedef name_info HUGE*name_pointer;
  218. typedef name_pointer*hash_pointer;
  219. #ifdef __TURBOC__
  220. extern char HUGE*byte_mem;
  221. extern name_info HUGE*name_dir;
  222. #else
  223. extern char byte_mem[];
  224. extern name_info name_dir[];
  225. #endif
  226. extern char HUGE*byte_mem_end;
  227. extern name_pointer name_dir_end;
  228. extern name_pointer name_ptr;
  229. extern char HUGE*byte_ptr;
  230. #ifdef __TURBOC__
  231. void far*allocsafe(unsigned long nunits,unsigned long unitsz);
  232. #endif
  233. extern name_pointer hash[];
  234. extern hash_pointer hash_end;
  235. extern hash_pointer h;
  236. extern int names_match(name_pointer,char*,int,eight_bits);
  237. extern name_pointer id_lookup(char*,char*,char);
  238.  
  239. extern name_pointer prefix_lookup(char*,char*);
  240. extern name_pointer section_lookup(char*,char*,int);
  241. extern void init_node(name_pointer);
  242. extern void init_p(name_pointer,eight_bits);
  243. extern void print_prefix_name(name_pointer);
  244. extern void print_section_name(name_pointer);
  245. extern void sprint_section_name(char*,name_pointer);
  246.  
  247. /*:9*//*10:*/
  248. #line 185 "ctangle.ch"
  249.  
  250. extern history;
  251. extern int wrap_up(void);
  252. extern void err_print(char*);
  253. extern void fatal(char*,char*);
  254. extern void overflow(char*);
  255.  
  256. /*:10*//*11:*/
  257. #line 185 "ctangle.ch"
  258.  
  259. extern include_depth;
  260. extern FILE*file[];
  261. extern FILE*change_file;
  262. extern char C_file_name[];
  263. extern char tex_file_name[];
  264. extern char idx_file_name[];
  265. extern char scn_file_name[];
  266. extern char file_name[][max_file_name_length];
  267.  
  268. extern char change_file_name[];
  269. extern line[];
  270. extern change_line;
  271. extern boolean input_has_ended;
  272. extern boolean changing;
  273. extern boolean web_file_open;
  274. extern boolean get_line(void);
  275. extern void check_complete(void);
  276. extern void reset_input(void);
  277.  
  278. /*:11*//*12:*/
  279. #line 185 "ctangle.ch"
  280.  
  281. typedef unsigned short sixteen_bits;
  282. extern sixteen_bits section_count;
  283. extern boolean changed_section[];
  284. extern boolean change_pending;
  285. extern boolean print_where;
  286.  
  287. /*:12*//*13:*/
  288. #line 185 "ctangle.ch"
  289.  
  290. extern int argc;
  291. extern char**argv;
  292. extern boolean flags[];
  293.  
  294. /*:13*//*14:*/
  295. #line 185 "ctangle.ch"
  296.  
  297. extern FILE*C_file;
  298. extern FILE*tex_file;
  299. extern FILE*idx_file;
  300. extern FILE*scn_file;
  301. extern FILE*active_file;
  302.  
  303. /*:14*//*15:*/
  304. #line 185 "ctangle.ch"
  305.  
  306. extern void common_init(void);
  307. extern void print_stats(void);
  308. #line 125 "ctangle.w"
  309.  
  310. /*:15*/
  311. #line 64 "ctangle.w"
  312.  
  313. /*16:*/
  314. #line 149 "ctangle.w"
  315.  
  316. typedef struct{
  317. #line 191 "ctangle.ch"
  318. eight_bits HUGE*tok_start;
  319. #line 152 "ctangle.w"
  320. sixteen_bits text_link;
  321. }text;
  322. typedef text*text_pointer;
  323.  
  324. /*:16*//*27:*/
  325. #line 293 "ctangle.w"
  326.  
  327. typedef struct{
  328. #line 281 "ctangle.ch"
  329. eight_bits HUGE*end_field;
  330. eight_bits HUGE*byte_field;
  331. #line 297 "ctangle.w"
  332. name_pointer name_field;
  333. text_pointer repl_field;
  334. sixteen_bits section_field;
  335. }output_state;
  336. typedef output_state*stack_pointer;
  337.  
  338. /*:27*/
  339. #line 65 "ctangle.w"
  340.  
  341. /*17:*/
  342. #line 156 "ctangle.w"
  343.  
  344. text text_info[max_texts];
  345. text_pointer text_info_end= text_info+max_texts-1;
  346. text_pointer text_ptr;
  347. #line 199 "ctangle.ch"
  348. #ifdef __TURBOC__
  349. eight_bits HUGE*tok_mem;
  350. eight_bits HUGE*tok_mem_end;
  351. #else
  352. eight_bits tok_mem[max_toks];
  353. eight_bits*tok_mem_end= tok_mem+max_toks-1;
  354. #endif
  355. eight_bits HUGE*tok_ptr;
  356. #line 163 "ctangle.w"
  357.  
  358. /*:17*//*23:*/
  359. #line 224 "ctangle.w"
  360.  
  361. text_pointer last_unnamed;
  362.  
  363. /*:23*//*28:*/
  364. #line 309 "ctangle.w"
  365.  
  366. output_state cur_state;
  367.  
  368. output_state stack[stack_size+1];
  369. stack_pointer stack_ptr;
  370. stack_pointer stack_end= stack+stack_size;
  371.  
  372. /*:28*//*32:*/
  373. #line 381 "ctangle.w"
  374.  
  375. int cur_val;
  376.  
  377. /*:32*//*36:*/
  378. #line 467 "ctangle.w"
  379.  
  380. eight_bits out_state;
  381. boolean protect;
  382.  
  383. /*:36*//*38:*/
  384. #line 496 "ctangle.w"
  385.  
  386. name_pointer output_files[max_files];
  387. name_pointer*cur_out_file,*end_output_files,*an_output_file;
  388. char cur_section_name_char;
  389. char output_file_name[longest_name];
  390.  
  391. /*:38*//*45:*/
  392. #line 592 "ctangle.w"
  393.  
  394. boolean output_defs_seen= 0;
  395.  
  396. #line 396 "ctangle.ch"
  397. /*:45*//*51:*/
  398. #line 699 "ctangle.w"
  399.  
  400. char translit[128][translit_length];
  401.  
  402. /*:51*//*56:*/
  403. #line 775 "ctangle.w"
  404.  
  405. eight_bits ccode[256];
  406.  
  407. /*:56*//*59:*/
  408. #line 831 "ctangle.w"
  409.  
  410. #line 832 "ctangle.w"
  411. boolean comment_continues= 0;
  412.  
  413. /*:59*//*61:*/
  414. #line 870 "ctangle.w"
  415.  
  416. name_pointer cur_section_name;
  417.  
  418. /*:61*//*75:*/
  419. #line 1180 "ctangle.w"
  420.  
  421. text_pointer cur_text;
  422. eight_bits next_control;
  423.  
  424. /*:75*//*82:*/
  425. #line 1327 "ctangle.w"
  426.  
  427. extern sixteen_bits section_count;
  428.  
  429. /*:82*/
  430. #line 66 "ctangle.w"
  431.  
  432. /*41:*/
  433. #line 346 "ctangle.ch"
  434.  
  435. #line 347 "ctangle.ch"
  436. static void phase_two(void);
  437.  
  438. /*:41*//*46:*/
  439. #line 396 "ctangle.ch"
  440.  
  441. static void output_defs(void);
  442.  
  443. /*:46*//*48:*/
  444. #line 421 "ctangle.ch"
  445.  
  446. #line 422 "ctangle.ch"
  447. static void out_char(eight_bits);
  448.  
  449. /*:48*//*90:*/
  450. #line 682 "ctangle.ch"
  451.  
  452. static void phase_one(void);
  453.  
  454. /*:90*//*92:*/
  455. #line 697 "ctangle.ch"
  456.  
  457. #line 698 "ctangle.ch"
  458. static void skip_limbo(void);
  459.  
  460. /*:92*//*96:*/
  461. #line 786 "ctangle.ch"
  462.  
  463. static eight_bits get_next(void);
  464. static eight_bits skip_ahead(void);
  465. static int skip_comment(boolean long_style);
  466. static void flush_buffer(void);
  467. static void get_output(void);
  468. static void pop_level(int);
  469. static void push_level(name_pointer p);
  470. static void scan_repl(eight_bits t);
  471. static void scan_section(void);
  472. static void store_two_bytes(sixteen_bits x);
  473.  
  474. /*:96*/
  475. #line 67 "ctangle.w"
  476.  
  477.  
  478. #line 165 "ctangle.ch"
  479. /*:1*//*3:*/
  480. #line 88 "ctangle.w"
  481.  
  482. #line 179 "ctangle.ch"
  483. int main(int ac,char**av)
  484. #line 92 "ctangle.w"
  485. {
  486. argc= ac;argv= av;
  487. program= ctangle;
  488. /*18:*/
  489. #line 164 "ctangle.w"
  490.  
  491. #line 212 "ctangle.ch"
  492. #ifdef __TURBOC__
  493. tok_mem= allocsafe(max_toks,sizeof(*tok_mem));
  494. tok_mem_end= tok_mem+max_toks-1;
  495. #endif
  496. text_info->tok_start= tok_ptr= tok_mem;
  497. #line 166 "ctangle.w"
  498. text_ptr= text_info+1;text_ptr->tok_start= tok_mem;
  499.  
  500.  
  501. /*:18*//*20:*/
  502. #line 174 "ctangle.w"
  503.  
  504. #line 222 "ctangle.ch"
  505. name_dir->equiv= (void HUGE*)text_info;
  506. #line 176 "ctangle.w"
  507.  
  508. /*:20*//*24:*/
  509. #line 227 "ctangle.w"
  510. last_unnamed= text_info;text_info->text_link= 0;
  511.  
  512. /*:24*//*39:*/
  513. #line 506 "ctangle.w"
  514.  
  515. cur_out_file= end_output_files= output_files+max_files;
  516.  
  517. /*:39*//*52:*/
  518. #line 702 "ctangle.w"
  519.  
  520. {
  521. int i;
  522. for(i= 0;i<128;i++)sprintf(translit[i],"X%02X",(unsigned)(128+i));
  523. }
  524.  
  525. /*:52*//*57:*/
  526. #line 778 "ctangle.w"
  527. {
  528. int c;
  529. for(c= 0;c<256;c++)ccode[c]= ignore;
  530. ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
  531. = ccode['*']= new_section;
  532. ccode['@']= '@';ccode['=']= string;
  533. ccode['d']= ccode['D']= definition;
  534. ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
  535. ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
  536. ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= 
  537. ccode['q']= ccode['Q']= control_text;
  538. ccode['h']= ccode['H']= output_defs_code;
  539. ccode['l']= ccode['L']= translit_code;
  540. ccode['&']= join;
  541. ccode['<']= ccode['(']= section_name;
  542. ccode['\'']= ord;
  543. }
  544.  
  545. /*:57*//*71:*/
  546. #line 1104 "ctangle.w"
  547. section_text[0]= ' ';
  548.  
  549. /*:71*/
  550. #line 95 "ctangle.w"
  551. ;
  552. common_init();
  553. if(show_banner)printf(banner);
  554. phase_one();
  555. phase_two();
  556. return wrap_up();
  557. }
  558.  
  559. /*:3*//*21:*/
  560. #line 180 "ctangle.w"
  561.  
  562. #line 232 "ctangle.ch"
  563. int names_match(name_pointer p,char*first,int l,eight_bits dummy)
  564.  
  565.  
  566.  
  567.  
  568. #line 185 "ctangle.w"
  569. {
  570. if(length(p)!=l)return 0;
  571. return!strncmp(first,p->byte_start,l);
  572. }
  573.  
  574. /*:21*//*22:*/
  575. #line 195 "ctangle.w"
  576.  
  577. #line 244 "ctangle.ch"
  578. void init_node(name_pointer node)
  579. #line 199 "ctangle.w"
  580. {
  581. #line 250 "ctangle.ch"
  582. node->equiv= (void HUGE*)text_info;
  583. #line 201 "ctangle.w"
  584. }
  585. #line 258 "ctangle.ch"
  586. void init_p(name_pointer dummy1,eight_bits dummy2)
  587. {}
  588. #line 204 "ctangle.w"
  589.  
  590. /*:22*//*26:*/
  591. #line 257 "ctangle.w"
  592.  
  593. #line 267 "ctangle.ch"
  594. static void store_two_bytes(sixteen_bits x)
  595. #line 261 "ctangle.w"
  596. {
  597. #line 274 "ctangle.ch"
  598. if(tok_ptr+2>tok_mem_end)overflow(get_string(MSG_OVERFLOW_CT26));
  599. #line 263 "ctangle.w"
  600. *tok_ptr++= x>>8;
  601. *tok_ptr++= x&0377;
  602. }
  603.  
  604. /*:26*//*30:*/
  605. #line 333 "ctangle.w"
  606.  
  607. #line 293 "ctangle.ch"
  608. static void push_level(name_pointer p)
  609. {
  610. if(stack_ptr==stack_end)overflow(get_string(MSG_OVERFLOW_CT30));
  611. #line 339 "ctangle.w"
  612. *stack_ptr= cur_state;
  613. stack_ptr++;
  614. if(p!=NULL){
  615. cur_name= p;cur_repl= (text_pointer)p->equiv;
  616. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  617. cur_section= 0;
  618. }
  619. }
  620.  
  621. /*:30*//*31:*/
  622. #line 352 "ctangle.w"
  623.  
  624. #line 303 "ctangle.ch"
  625. static void pop_level(int flag)
  626. #line 356 "ctangle.w"
  627. {
  628. if(flag&&cur_repl->text_link<section_flag){
  629. cur_repl= cur_repl->text_link+text_info;
  630. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  631. return;
  632. }
  633. stack_ptr--;
  634. if(stack_ptr>stack)cur_state= *stack_ptr;
  635. }
  636.  
  637. /*:31*//*33:*/
  638. #line 388 "ctangle.w"
  639.  
  640. #line 310 "ctangle.ch"
  641. static void get_output(void)
  642. #line 391 "ctangle.w"
  643. {
  644. sixteen_bits a;
  645. restart:if(stack_ptr==stack)return;
  646. if(cur_byte==cur_end){
  647. cur_val= -((int)cur_section);
  648. pop_level(1);
  649. if(cur_val==0)goto restart;
  650. out_char(section_number);return;
  651. }
  652. a= *cur_byte++;
  653. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  654. C_putc(a);
  655. else if(a<0200)out_char(a);
  656. else{
  657. a= (a-0200)*0400+*cur_byte++;
  658. switch(a/024000){
  659. case 0:cur_val= a;out_char(identifier);break;
  660. case 1:if(a==output_defs_flag)output_defs();
  661. else/*34:*/
  662. #line 420 "ctangle.w"
  663.  
  664. {
  665. a-= 024000;
  666. #line 319 "ctangle.ch"
  667. if((a+name_dir)->equiv!=(void HUGE*)text_info)push_level(a+name_dir);
  668. else if(a!=0){
  669. printf(get_string(MSG_ERROR_CT34));
  670. #line 426 "ctangle.w"
  671. print_section_name(a+name_dir);err_print(">");
  672.  
  673. }
  674. goto restart;
  675. }
  676.  
  677. /*:34*/
  678. #line 409 "ctangle.w"
  679. ;
  680. break;
  681. default:cur_val= a-050000;if(cur_val>0)cur_section= cur_val;
  682. out_char(section_number);
  683. }
  684. }
  685. }
  686.  
  687. /*:33*//*37:*/
  688. #line 475 "ctangle.w"
  689.  
  690. #line 328 "ctangle.ch"
  691. static void flush_buffer(void)
  692. #line 478 "ctangle.w"
  693. {
  694. C_putc('\n');
  695. if(cur_line%100==0&&show_progress){
  696. printf(".");
  697. if(cur_line%500==0)printf("%d",cur_line);
  698. update_terminal;
  699. }
  700. cur_line++;
  701. }
  702.  
  703. /*:37*//*42:*/
  704. #line 349 "ctangle.ch"
  705.  
  706. static void phase_two(void){
  707. #line 532 "ctangle.w"
  708. web_file_open= 0;
  709. cur_line= 1;
  710. /*29:*/
  711. #line 322 "ctangle.w"
  712.  
  713. stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;
  714. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;
  715.  
  716. /*:29*/
  717. #line 534 "ctangle.w"
  718. ;
  719. /*44:*/
  720. #line 588 "ctangle.w"
  721.  
  722. if(!output_defs_seen)
  723. output_defs();
  724.  
  725. /*:44*/
  726. #line 535 "ctangle.w"
  727. ;
  728. if(text_info->text_link==0&&cur_out_file==end_output_files){
  729. #line 357 "ctangle.ch"
  730. printf(get_string(MSG_WARNING_CT42));mark_harmless;
  731. #line 538 "ctangle.w"
  732.  
  733. }
  734. else{
  735. if(cur_out_file==end_output_files){
  736. if(show_progress)
  737. #line 364 "ctangle.ch"
  738. printf(get_string(MSG_PROGRESS_CT42_1),C_file_name);
  739. #line 544 "ctangle.w"
  740. }
  741. else{
  742. if(show_progress){
  743. #line 371 "ctangle.ch"
  744. printf(get_string(MSG_PROGRESS_CT42_2));
  745. #line 548 "ctangle.w"
  746.  
  747. printf(" (%s)",C_file_name);
  748. update_terminal;
  749. }
  750. if(text_info->text_link==0)goto writeloop;
  751. }
  752. while(stack_ptr>stack)get_output();
  753. flush_buffer();
  754. writeloop:/*43:*/
  755. #line 565 "ctangle.w"
  756.  
  757. for(an_output_file= end_output_files;an_output_file>cur_out_file;){
  758. an_output_file--;
  759. sprint_section_name(output_file_name,*an_output_file);
  760. fclose(C_file);
  761. C_file= fopen(output_file_name,"w");
  762. #line 385 "ctangle.ch"
  763. if(C_file==0)fatal(get_string(MSG_FATAL_CO78),output_file_name);
  764. #line 572 "ctangle.w"
  765.  
  766. printf("\n(%s)",output_file_name);update_terminal;
  767. cur_line= 1;
  768. stack_ptr= stack+1;
  769. cur_name= (*an_output_file);
  770. cur_repl= (text_pointer)cur_name->equiv;
  771. cur_byte= cur_repl->tok_start;
  772. cur_end= (cur_repl+1)->tok_start;
  773. while(stack_ptr>stack)get_output();
  774. flush_buffer();
  775. }
  776.  
  777. /*:43*/
  778. #line 556 "ctangle.w"
  779. ;
  780. #line 378 "ctangle.ch"
  781. if(show_happiness)printf(get_string(MSG_PROGRESS_CT42_3));
  782. #line 558 "ctangle.w"
  783. }
  784. }
  785.  
  786. /*:42*//*47:*/
  787. #line 399 "ctangle.ch"
  788.  
  789. static void output_defs(void)
  790. #line 601 "ctangle.w"
  791. {
  792. sixteen_bits a;
  793. push_level(NULL);
  794. for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)
  795. if(cur_text->text_link==0){
  796. cur_byte= cur_text->tok_start;
  797. cur_end= (cur_text+1)->tok_start;
  798. C_printf("%s","#define ");
  799. out_state= normal;
  800. protect= 1;
  801. while(cur_byte<cur_end){
  802. a= *cur_byte++;
  803. if(cur_byte==cur_end&&a=='\n')break;
  804. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  805. C_putc(a);
  806.  
  807. else if(a<0200)out_char(a);
  808. else{
  809. a= (a-0200)*0400+*cur_byte++;
  810. if(a<024000){
  811. cur_val= a;out_char(identifier);
  812. }
  813. #line 407 "ctangle.ch"
  814. else if(a<050000){confusion(get_string(MSG_CONFUSION_CT47));}
  815. #line 624 "ctangle.w"
  816. else{
  817. cur_val= a-050000;cur_section= cur_val;out_char(section_number);
  818. }
  819.  
  820. }
  821. }
  822. protect= 0;
  823. flush_buffer();
  824. }
  825. pop_level(0);
  826. }
  827.  
  828. /*:47*//*49:*/
  829. #line 424 "ctangle.ch"
  830.  
  831. static void out_char(eight_bits cur_char)
  832. {
  833. char HUGE*j;
  834. char HUGE*k;
  835. #line 650 "ctangle.w"
  836. restart:
  837. switch(cur_char){
  838. case'\n':if(protect)C_putc(' ');
  839. if(protect||out_state==verbatim)C_putc('\\');
  840. flush_buffer();if(out_state!=verbatim)out_state= normal;break;
  841. #line 438 "ctangle.ch"
  842. /*53:*/
  843. #line 708 "ctangle.w"
  844.  
  845. case identifier:
  846. if(out_state==num_or_id)C_putc(' ');
  847. j= (cur_val+name_dir)->byte_start;
  848. k= (cur_val+name_dir+1)->byte_start;
  849. while(j<k){
  850. if((unsigned char)(*j)<0200)C_putc(*j);
  851.  
  852. else C_printf("%s",translit[(unsigned char)(*j)-0200]);
  853. j++;
  854. }
  855. out_state= num_or_id;break;
  856.  
  857. /*:53*/
  858. #line 438 "ctangle.ch"
  859. ;
  860. /*54:*/
  861. #line 721 "ctangle.w"
  862.  
  863. case section_number:
  864. if(cur_val>0)C_printf("/*%d:*/",cur_val);
  865. else if(cur_val<0)C_printf("/*:%d*/",-cur_val);
  866. else if(protect){
  867. cur_byte+= 4;
  868. cur_char= '\n';
  869. goto restart;
  870. }else{
  871. sixteen_bits a;
  872. a= 0400**cur_byte++;
  873. a+= *cur_byte++;
  874. C_printf("\n#line %d \"",a);
  875.  
  876. cur_val= *cur_byte++;
  877. cur_val= 0400*(cur_val-0200)+*cur_byte++;
  878. for(j= (cur_val+name_dir)->byte_start,k= (cur_val+name_dir+1)->byte_start;
  879. j<k;j++)C_putc(*j);
  880. C_printf("%s","\"\n");
  881. }
  882. break;
  883.  
  884. /*:54*/
  885. #line 439 "ctangle.ch"
  886. ;
  887. /*50:*/
  888. #line 670 "ctangle.w"
  889.  
  890. case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;
  891. case minus_minus:C_putc('-');C_putc('-');out_state= normal;break;
  892. case minus_gt:C_putc('-');C_putc('>');out_state= normal;break;
  893. case gt_gt:C_putc('>');C_putc('>');out_state= normal;break;
  894. case eq_eq:C_putc('=');C_putc('=');out_state= normal;break;
  895. case lt_lt:C_putc('<');C_putc('<');out_state= normal;break;
  896. case gt_eq:C_putc('>');C_putc('=');out_state= normal;break;
  897. case lt_eq:C_putc('<');C_putc('=');out_state= normal;break;
  898. case not_eq:C_putc('!');C_putc('=');out_state= normal;break;
  899. case and_and:C_putc('&');C_putc('&');out_state= normal;break;
  900. case or_or:C_putc('|');C_putc('|');out_state= normal;break;
  901. case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal;
  902. break;
  903. case colon_colon:C_putc(':');C_putc(':');out_state= normal;break;
  904. case period_ast:C_putc('.');C_putc('*');out_state= normal;break;
  905. case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal;
  906. break;
  907.  
  908. /*:50*/
  909. #line 440 "ctangle.ch"
  910. ;
  911. #line 658 "ctangle.w"
  912. case'=':C_putc('=');C_putc(' ');out_state= normal;break;
  913. case join:out_state= unbreakable;break;
  914. case constant:if(out_state==verbatim){
  915. out_state= num_or_id;break;
  916. }
  917. if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break;
  918. case string:if(out_state==verbatim)out_state= normal;
  919. else out_state= verbatim;break;
  920. default:C_putc(cur_char);out_state= normal;break;
  921. }
  922. }
  923.  
  924. /*:49*//*58:*/
  925. #line 799 "ctangle.w"
  926.  
  927. #line 447 "ctangle.ch"
  928. static eight_bits skip_ahead(void)
  929. #line 802 "ctangle.w"
  930. {
  931. eight_bits c;
  932. while(1){
  933. if(loc>limit&&(get_line()==0))return(new_section);
  934. *(limit+1)= '@';
  935. while(*loc!='@')loc++;
  936. if(loc<=limit){
  937. loc++;c= ccode[(eight_bits)*loc];loc++;
  938. if(c!=ignore||*(loc-1)=='>')return(c);
  939. }
  940. }
  941. }
  942.  
  943. /*:58*//*60:*/
  944. #line 834 "ctangle.w"
  945.  
  946. #line 461 "ctangle.ch"
  947. static int skip_comment(boolean is_long_comment)
  948. #line 837 "ctangle.w"
  949. {
  950. char c;
  951. while(1){
  952. if(loc>limit){
  953. if(is_long_comment){
  954. if(get_line())return(comment_continues= 1);
  955. else{
  956. #line 468 "ctangle.ch"
  957. err_print(get_string(MSG_ERROR_CT60_1));
  958. #line 845 "ctangle.w"
  959.  
  960. return(comment_continues= 0);
  961. }
  962. }
  963. else return(comment_continues= 0);
  964. }
  965. c= *(loc++);
  966. if(is_long_comment&&c=='*'&&*loc=='/'){
  967. loc++;return(comment_continues= 0);
  968. }
  969. if(c=='@'){
  970. if(ccode[(eight_bits)*loc]==new_section){
  971. #line 475 "ctangle.ch"
  972. err_print(get_string(MSG_ERROR_CT60_2));loc--;
  973. #line 858 "ctangle.w"
  974.  
  975. return(comment_continues= 0);
  976. }
  977. else loc++;
  978. }
  979. }
  980. }
  981.  
  982. /*:60*//*63:*/
  983. #line 884 "ctangle.w"
  984.  
  985. #line 482 "ctangle.ch"
  986. static eight_bits get_next(void)
  987. #line 887 "ctangle.w"
  988. {
  989. static int preprocessing= 0;
  990. eight_bits c;
  991. while(1){
  992. if(loc>limit){
  993. if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
  994. if(get_line()==0)return(new_section);
  995. else if(print_where){
  996. print_where= 0;
  997. /*77:*/
  998. #line 1207 "ctangle.w"
  999.  
  1000. store_two_bytes(0150000);
  1001. if(changing)id_first= change_file_name;
  1002. else id_first= cur_file_name;
  1003. id_loc= id_first+strlen(id_first);
  1004. if(changing)store_two_bytes((sixteen_bits)change_line);
  1005. else store_two_bytes((sixteen_bits)cur_line);
  1006. #line 608 "ctangle.ch"
  1007. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1008. #line 1215 "ctangle.w"
  1009. app_repl(a%0400);}
  1010.  
  1011. /*:77*/
  1012. #line 896 "ctangle.w"
  1013. ;
  1014. }
  1015. else return('\n');
  1016. }
  1017. c= *loc;
  1018. if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
  1019. skip_comment(comment_continues||*(loc+1)=='*');
  1020.  
  1021. if(comment_continues)return('\n');
  1022. else continue;
  1023. }
  1024. loc++;
  1025. if(xisdigit(c)||c=='\\'||c=='.')/*66:*/
  1026. #line 962 "ctangle.w"
  1027. {
  1028. id_first= loc-1;
  1029. if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
  1030. if(*id_first=='\\')while(xisdigit(*loc))loc++;
  1031. else{
  1032. if(*id_first=='0'){
  1033. if(*loc=='x'||*loc=='X'){
  1034. loc++;while(xisxdigit(*loc))loc++;goto found;
  1035. }
  1036. }
  1037. while(xisdigit(*loc))loc++;
  1038. if(*loc=='.'){
  1039. loc++;
  1040. while(xisdigit(*loc))loc++;
  1041. }
  1042. if(*loc=='e'||*loc=='E'){
  1043. if(*++loc=='+'||*loc=='-')loc++;
  1044. while(xisdigit(*loc))loc++;
  1045. }
  1046. }
  1047. found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
  1048. ||*loc=='f'||*loc=='F')loc++;
  1049. id_loc= loc;
  1050. return(constant);
  1051. }
  1052.  
  1053. /*:66*/
  1054. #line 908 "ctangle.w"
  1055.  
  1056. else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
  1057. /*67:*/
  1058. #line 993 "ctangle.w"
  1059. {
  1060. char delim= c;
  1061. id_first= section_text+1;
  1062. id_loc= section_text;*++id_loc= delim;
  1063. if(delim=='L'){
  1064. delim= *loc++;*++id_loc= delim;
  1065. }
  1066. while(1){
  1067. if(loc>=limit){
  1068. if(*(limit-1)!='\\'){
  1069. #line 489 "ctangle.ch"
  1070. err_print(get_string(MSG_ERROR_CT67_1));loc= limit;break;
  1071. #line 1004 "ctangle.w"
  1072.  
  1073. }
  1074. if(get_line()==0){
  1075. #line 496 "ctangle.ch"
  1076. err_print(get_string(MSG_ERROR_CT67_2));loc= buffer;break;
  1077. #line 1008 "ctangle.w"
  1078.  
  1079. }
  1080. else if(++id_loc<=section_text_end)*id_loc= '\n';
  1081.  
  1082. }
  1083. if((c= *loc++)==delim){
  1084. if(++id_loc<=section_text_end)*id_loc= c;
  1085. break;
  1086. }
  1087. if(c=='\\'){
  1088. if(loc>=limit)continue;
  1089. if(++id_loc<=section_text_end)*id_loc= '\\';
  1090. c= *loc++;
  1091. }
  1092. if(++id_loc<=section_text_end)*id_loc= c;
  1093. }
  1094. if(id_loc>=section_text_end){
  1095. #line 503 "ctangle.ch"
  1096. printf(get_string(MSG_ERROR_CT67_3));
  1097. #line 1026 "ctangle.w"
  1098.  
  1099. term_write(section_text+1,25);
  1100. err_print("...");
  1101. }
  1102. id_loc++;
  1103. return(string);
  1104. }
  1105.  
  1106. /*:67*/
  1107. #line 910 "ctangle.w"
  1108.  
  1109. else if(isalpha(c)||isxalpha(c)||ishigh(c))
  1110. /*65:*/
  1111. #line 956 "ctangle.w"
  1112. {
  1113. id_first= --loc;
  1114. while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
  1115. id_loc= loc;return(identifier);
  1116. }
  1117.  
  1118. /*:65*/
  1119. #line 912 "ctangle.w"
  1120.  
  1121. else if(c=='@')/*68:*/
  1122. #line 1037 "ctangle.w"
  1123. {
  1124. c= ccode[(eight_bits)*loc++];
  1125. switch(c){
  1126. case ignore:continue;
  1127. case output_defs_code:output_defs_seen= 1;return(c);
  1128. #line 510 "ctangle.ch"
  1129. case translit_code:err_print(get_string(MSG_ERROR_CT68_1));continue;
  1130. #line 1043 "ctangle.w"
  1131.  
  1132. case control_text:while((c= skip_ahead())=='@');
  1133.  
  1134. if(*(loc-1)!='>')
  1135. #line 517 "ctangle.ch"
  1136. err_print(get_string(MSG_ERROR_CT68_2));
  1137. #line 1048 "ctangle.w"
  1138.  
  1139. continue;
  1140. case section_name:
  1141. cur_section_name_char= *(loc-1);
  1142. /*70:*/
  1143. #line 1086 "ctangle.w"
  1144. {
  1145. char*k;
  1146. /*72:*/
  1147. #line 1106 "ctangle.w"
  1148.  
  1149. k= section_text;
  1150. while(1){
  1151. if(loc>limit&&get_line()==0){
  1152. #line 538 "ctangle.ch"
  1153. err_print(get_string(MSG_ERROR_CT72_1));
  1154. #line 1111 "ctangle.w"
  1155.  
  1156. loc= buffer+1;break;
  1157. }
  1158. c= *loc;
  1159. /*73:*/
  1160. #line 1130 "ctangle.w"
  1161.  
  1162. if(c=='@'){
  1163. c= *(loc+1);
  1164. if(c=='>'){
  1165. loc+= 2;break;
  1166. }
  1167. if(ccode[(eight_bits)c]==new_section){
  1168. #line 552 "ctangle.ch"
  1169. err_print(get_string(MSG_ERROR_CT73_1));break;
  1170. #line 1138 "ctangle.w"
  1171.  
  1172. }
  1173. if(ccode[(eight_bits)c]==section_name){
  1174. #line 559 "ctangle.ch"
  1175. err_print(get_string(MSG_ERROR_CT73_2));break;
  1176. #line 1142 "ctangle.w"
  1177.  
  1178. }
  1179. *(++k)= '@';loc++;
  1180. }
  1181.  
  1182. /*:73*/
  1183. #line 1115 "ctangle.w"
  1184. ;
  1185. loc++;if(k<section_text_end)k++;
  1186. if(xisspace(c)){
  1187. c= ' ';if(*(k-1)==' ')k--;
  1188. }
  1189. *k= c;
  1190. }
  1191. if(k>=section_text_end){
  1192. #line 545 "ctangle.ch"
  1193. printf(get_string(MSG_ERROR_CT72_2));
  1194. #line 1124 "ctangle.w"
  1195.  
  1196. term_write(section_text+1,25);
  1197. printf("...");mark_harmless;
  1198. }
  1199. if(*k==' '&&k>section_text)k--;
  1200.  
  1201. /*:72*/
  1202. #line 1088 "ctangle.w"
  1203. ;
  1204. if(k-section_text>3&&strncmp(k-2,"...",3)==0)
  1205. cur_section_name= section_lookup(section_text+1,k-3,1);
  1206. else cur_section_name= section_lookup(section_text+1,k,0);
  1207. if(cur_section_name_char=='(')
  1208. /*40:*/
  1209. #line 510 "ctangle.w"
  1210.  
  1211. {
  1212. if(cur_out_file>output_files){
  1213. for(an_output_file= cur_out_file;
  1214. an_output_file<end_output_files;an_output_file++)
  1215. if(*an_output_file==cur_section_name)break;
  1216. if(an_output_file==end_output_files)
  1217. *--cur_out_file= cur_section_name;
  1218. }else{
  1219. #line 335 "ctangle.ch"
  1220. overflow(get_string(MSG_OVERFLOW_CT40));
  1221. #line 520 "ctangle.w"
  1222. }
  1223. }
  1224.  
  1225. /*:40*/
  1226. #line 1094 "ctangle.w"
  1227. ;
  1228. return(section_name);
  1229. }
  1230.  
  1231. /*:70*/
  1232. #line 1052 "ctangle.w"
  1233. ;
  1234. case string:/*74:*/
  1235. #line 1152 "ctangle.w"
  1236. {
  1237. id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
  1238. while(*loc!='@'||*(loc+1)!='>')loc++;
  1239. #line 566 "ctangle.ch"
  1240. if(loc>=limit)err_print(get_string(MSG_ERROR_CT74));
  1241. #line 1156 "ctangle.w"
  1242.  
  1243. id_loc= loc;loc+= 2;
  1244. return(string);
  1245. }
  1246.  
  1247. /*:74*/
  1248. #line 1053 "ctangle.w"
  1249. ;
  1250. case ord:/*69:*/
  1251. #line 1065 "ctangle.w"
  1252.  
  1253. id_first= loc;
  1254. if(*loc=='\\'){
  1255. if(*++loc=='\'')loc++;
  1256. }
  1257. while(*loc!='\''){
  1258. if(*loc=='@'){
  1259. if(*(loc+1)!='@')
  1260. #line 524 "ctangle.ch"
  1261. err_print(get_string(MSG_ERROR_CT69));
  1262. #line 1074 "ctangle.w"
  1263.  
  1264. else loc++;
  1265. }
  1266. loc++;
  1267. if(loc>limit){
  1268. #line 531 "ctangle.ch"
  1269. err_print(get_string(MSG_ERROR_CT67_1));loc= limit-1;break;
  1270. #line 1080 "ctangle.w"
  1271.  
  1272. }
  1273. }
  1274. loc++;
  1275. return(ord);
  1276.  
  1277. /*:69*/
  1278. #line 1054 "ctangle.w"
  1279. ;
  1280. default:return(c);
  1281. }
  1282. }
  1283.  
  1284. /*:68*/
  1285. #line 913 "ctangle.w"
  1286.  
  1287. else if(xisspace(c)){
  1288. if(!preprocessing||loc>limit)continue;
  1289.  
  1290. else return(' ');
  1291. }
  1292. else if(c=='#'&&loc==buffer+1)preprocessing= 1;
  1293. mistake:/*64:*/
  1294. #line 934 "ctangle.w"
  1295.  
  1296. switch(c){
  1297. case'+':if(*loc=='+')compress(plus_plus);break;
  1298. case'-':if(*loc=='-'){compress(minus_minus);}
  1299. else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
  1300. else compress(minus_gt);break;
  1301. case'.':if(*loc=='*'){compress(period_ast);}
  1302. else if(*loc=='.'&&*(loc+1)=='.'){
  1303. loc++;compress(dot_dot_dot);
  1304. }
  1305. break;
  1306. case':':if(*loc==':')compress(colon_colon);break;
  1307. case'=':if(*loc=='=')compress(eq_eq);break;
  1308. case'>':if(*loc=='='){compress(gt_eq);}
  1309. else if(*loc=='>')compress(gt_gt);break;
  1310. case'<':if(*loc=='='){compress(lt_eq);}
  1311. else if(*loc=='<')compress(lt_lt);break;
  1312. case'&':if(*loc=='&')compress(and_and);break;
  1313. case'|':if(*loc=='|')compress(or_or);break;
  1314. case'!':if(*loc=='=')compress(not_eq);break;
  1315. }
  1316.  
  1317. /*:64*/
  1318. #line 920 "ctangle.w"
  1319.  
  1320. return(c);
  1321. }
  1322. }
  1323.  
  1324. /*:63*//*76:*/
  1325. #line 1184 "ctangle.w"
  1326.  
  1327. #line 581 "ctangle.ch"
  1328. static void scan_repl(eight_bits t)
  1329. #line 1188 "ctangle.w"
  1330. {
  1331. sixteen_bits a;
  1332. if(t==section_name){/*77:*/
  1333. #line 1207 "ctangle.w"
  1334.  
  1335. store_two_bytes(0150000);
  1336. if(changing)id_first= change_file_name;
  1337. else id_first= cur_file_name;
  1338. id_loc= id_first+strlen(id_first);
  1339. if(changing)store_two_bytes((sixteen_bits)change_line);
  1340. else store_two_bytes((sixteen_bits)cur_line);
  1341. #line 608 "ctangle.ch"
  1342. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1343. #line 1215 "ctangle.w"
  1344. app_repl(a%0400);}
  1345.  
  1346. /*:77*/
  1347. #line 1190 "ctangle.w"
  1348. ;}
  1349. while(1)switch(a= get_next()){
  1350. /*78:*/
  1351. #line 1217 "ctangle.w"
  1352.  
  1353. #line 615 "ctangle.ch"
  1354. case identifier:a= id_lookup(id_first,id_loc,' ')-name_dir;
  1355. #line 1219 "ctangle.w"
  1356. app_repl((a/0400)+0200);
  1357. app_repl(a%0400);break;
  1358. case section_name:if(t!=section_name)goto done;
  1359. else{
  1360. /*79:*/
  1361. #line 1245 "ctangle.w"
  1362. {
  1363. char*try_loc= loc;
  1364. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1365. if(*try_loc=='+'&&try_loc<limit)try_loc++;
  1366. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1367. #line 629 "ctangle.ch"
  1368. if(*try_loc=='=')err_print(get_string(MSG_ERROR_CT79));
  1369. #line 1251 "ctangle.w"
  1370.  
  1371.  
  1372.  
  1373. }
  1374.  
  1375. /*:79*/
  1376. #line 1223 "ctangle.w"
  1377. ;
  1378. a= cur_section_name-name_dir;
  1379. app_repl((a/0400)+0250);
  1380. app_repl(a%0400);
  1381. /*77:*/
  1382. #line 1207 "ctangle.w"
  1383.  
  1384. store_two_bytes(0150000);
  1385. if(changing)id_first= change_file_name;
  1386. else id_first= cur_file_name;
  1387. id_loc= id_first+strlen(id_first);
  1388. if(changing)store_two_bytes((sixteen_bits)change_line);
  1389. else store_two_bytes((sixteen_bits)cur_line);
  1390. #line 608 "ctangle.ch"
  1391. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1392. #line 1215 "ctangle.w"
  1393. app_repl(a%0400);}
  1394.  
  1395. /*:77*/
  1396. #line 1227 "ctangle.w"
  1397. ;break;
  1398. }
  1399. case output_defs_code:
  1400. a= output_defs_flag;
  1401. app_repl((a/0400)+0200);
  1402. app_repl(a%0400);
  1403. /*77:*/
  1404. #line 1207 "ctangle.w"
  1405.  
  1406. store_two_bytes(0150000);
  1407. if(changing)id_first= change_file_name;
  1408. else id_first= cur_file_name;
  1409. id_loc= id_first+strlen(id_first);
  1410. if(changing)store_two_bytes((sixteen_bits)change_line);
  1411. else store_two_bytes((sixteen_bits)cur_line);
  1412. #line 608 "ctangle.ch"
  1413. {int a= id_lookup(id_first,id_loc,' ')-name_dir;app_repl((a/0400)+0200);
  1414. #line 1215 "ctangle.w"
  1415. app_repl(a%0400);}
  1416.  
  1417. /*:77*/
  1418. #line 1233 "ctangle.w"
  1419. ;break;
  1420. case constant:case string:
  1421. /*80:*/
  1422. #line 1256 "ctangle.w"
  1423.  
  1424. app_repl(a);
  1425. while(id_first<id_loc){
  1426. if(*id_first=='@'){
  1427. if(*(id_first+1)=='@')id_first++;
  1428. #line 636 "ctangle.ch"
  1429. else err_print(get_string(MSG_ERROR_CT80));
  1430. #line 1262 "ctangle.w"
  1431.  
  1432. }
  1433. app_repl(*id_first++);
  1434. }
  1435. app_repl(a);break;
  1436.  
  1437. /*:80*/
  1438. #line 1235 "ctangle.w"
  1439. ;
  1440. case ord:
  1441. /*81:*/
  1442. #line 1272 "ctangle.w"
  1443. {
  1444. int c= (eight_bits)*id_first;
  1445. if(c=='\\'){
  1446. c= *++id_first;
  1447. if(c>='0'&&c<='7'){
  1448. c-= '0';
  1449. if(*(id_first+1)>='0'&&*(id_first+1)<='7'){
  1450. c= 8*c+*(++id_first)-'0';
  1451. if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32)
  1452. c= 8*c+*(++id_first)-'0';
  1453. }
  1454. }
  1455. else switch(c){
  1456. case't':c= '\t';break;
  1457. case'n':c= '\n';break;
  1458. case'b':c= '\b';break;
  1459. case'f':c= '\f';break;
  1460. case'v':c= '\v';break;
  1461. case'r':c= '\r';break;
  1462. case'a':c= '\7';break;
  1463. case'?':c= '?';break;
  1464. case'x':
  1465. if(xisdigit(*(id_first+1)))c= *(++id_first)-'0';
  1466. else if(xisxdigit(*(id_first+1))){
  1467. ++id_first;
  1468. c= toupper(*id_first)-'A'+10;
  1469. }
  1470. if(xisdigit(*(id_first+1)))c= 16*c+*(++id_first)-'0';
  1471. else if(xisxdigit(*(id_first+1))){
  1472. ++id_first;
  1473. c= 16*c+toupper(*id_first)-'A'+10;
  1474. }
  1475. break;
  1476. case'\\':c= '\\';break;
  1477. case'\'':c= '\'';break;
  1478. case'\"':c= '\"';break;
  1479. #line 643 "ctangle.ch"
  1480. default:err_print(get_string(MSG_ERROR_CT81));
  1481. #line 1309 "ctangle.w"
  1482.  
  1483. }
  1484. }
  1485.  
  1486. app_repl(constant);
  1487. if(c>=100)app_repl('0'+c/100);
  1488. if(c>=10)app_repl('0'+(c/10)%10);
  1489. app_repl('0'+c%10);
  1490. app_repl(constant);
  1491. }
  1492. break;
  1493.  
  1494. /*:81*/
  1495. #line 1237 "ctangle.w"
  1496. ;
  1497. case definition:case format_code:case begin_C:if(t!=section_name)goto done;
  1498. else{
  1499. #line 622 "ctangle.ch"
  1500. err_print(get_string(MSG_ERROR_CT78));continue;
  1501. #line 1241 "ctangle.w"
  1502.  
  1503. }
  1504. case new_section:goto done;
  1505.  
  1506. /*:78*/
  1507. #line 1195 "ctangle.w"
  1508.  
  1509. #line 590 "ctangle.ch"
  1510. case')':
  1511.  
  1512.  
  1513. app_repl(a);if(t==macro)app_repl(' ');break;
  1514. default:app_repl(a);
  1515. #line 1197 "ctangle.w"
  1516. }
  1517. done:next_control= (eight_bits)a;
  1518. #line 601 "ctangle.ch"
  1519. if(text_ptr>text_info_end)overflow(get_string(MSG_OVERFLOW_CT76));
  1520. #line 1200 "ctangle.w"
  1521. cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr;
  1522. }
  1523.  
  1524. /*:76*//*83:*/
  1525. #line 1334 "ctangle.w"
  1526.  
  1527. #line 650 "ctangle.ch"
  1528. static void scan_section(void)
  1529. #line 1337 "ctangle.w"
  1530. {
  1531. name_pointer p;
  1532. text_pointer q;
  1533. sixteen_bits a;
  1534. section_count++;
  1535. if(*(loc-1)=='*'&&show_progress){
  1536. printf("*%d",section_count);update_terminal;
  1537. }
  1538. next_control= 0;
  1539. while(1){
  1540. /*84:*/
  1541. #line 1372 "ctangle.w"
  1542.  
  1543. while(next_control<definition)
  1544.  
  1545. if((next_control= skip_ahead())==section_name){
  1546. loc-= 2;next_control= get_next();
  1547. }
  1548.  
  1549. /*:84*/
  1550. #line 1348 "ctangle.w"
  1551. ;
  1552. if(next_control==definition){
  1553. /*85:*/
  1554. #line 1379 "ctangle.w"
  1555. {
  1556. while((next_control= get_next())=='\n');
  1557. if(next_control!=identifier){
  1558. #line 657 "ctangle.ch"
  1559. err_print(get_string(MSG_ERROR_CT85));
  1560. #line 1383 "ctangle.w"
  1561.  
  1562. continue;
  1563. }
  1564. #line 665 "ctangle.ch"
  1565. app_repl(((a= id_lookup(id_first,id_loc,' ')-name_dir)/0400)+0200);
  1566. #line 1387 "ctangle.w"
  1567.  
  1568. app_repl(a%0400);
  1569. if(*loc!='('){
  1570. app_repl(string);app_repl(' ');app_repl(string);
  1571. }
  1572. print_where= 0;scan_repl(macro);
  1573. cur_text->text_link= 0;
  1574. }
  1575.  
  1576. /*:85*/
  1577. #line 1350 "ctangle.w"
  1578.  
  1579. continue;
  1580. }
  1581. if(next_control==begin_C){
  1582. p= name_dir;break;
  1583. }
  1584. if(next_control==section_name){
  1585. p= cur_section_name;
  1586. /*86:*/
  1587. #line 1404 "ctangle.w"
  1588.  
  1589. while((next_control= get_next())=='+');
  1590. if(next_control!='='&&next_control!=eq_eq)
  1591. continue;
  1592.  
  1593. /*:86*/
  1594. #line 1358 "ctangle.w"
  1595. ;
  1596. break;
  1597. }
  1598. return;
  1599. }
  1600. /*87:*/
  1601. #line 1409 "ctangle.w"
  1602.  
  1603. /*88:*/
  1604. #line 1414 "ctangle.w"
  1605.  
  1606. store_two_bytes((sixteen_bits)(0150000+section_count));
  1607.  
  1608.  
  1609. /*:88*/
  1610. #line 1410 "ctangle.w"
  1611. ;
  1612. scan_repl(section_name);
  1613. /*89:*/
  1614. #line 1418 "ctangle.w"
  1615.  
  1616. if(p==name_dir||p==0){
  1617. (last_unnamed)->text_link= cur_text-text_info;last_unnamed= cur_text;
  1618. }
  1619. #line 671 "ctangle.ch"
  1620. else if(p->equiv==(void HUGE*)text_info)p->equiv= (void HUGE*)cur_text;
  1621. #line 1423 "ctangle.w"
  1622.  
  1623. else{
  1624. q= (text_pointer)p->equiv;
  1625. while(q->text_link<section_flag)
  1626. q= q->text_link+text_info;
  1627. q->text_link= cur_text-text_info;
  1628. }
  1629. cur_text->text_link= section_flag;
  1630.  
  1631.  
  1632. #line 682 "ctangle.ch"
  1633. /*:89*/
  1634. #line 1412 "ctangle.w"
  1635. ;
  1636.  
  1637. /*:87*/
  1638. #line 1363 "ctangle.w"
  1639. ;
  1640. }
  1641.  
  1642. /*:83*//*91:*/
  1643. #line 685 "ctangle.ch"
  1644.  
  1645. static void phase_one(void){
  1646. #line 1439 "ctangle.w"
  1647. phase= 1;
  1648. section_count= 0;
  1649. reset_input();
  1650. skip_limbo();
  1651. while(!input_has_ended)scan_section();
  1652. check_complete();
  1653. phase= 2;
  1654. }
  1655.  
  1656. /*:91*//*93:*/
  1657. #line 700 "ctangle.ch"
  1658.  
  1659. static void skip_limbo(void)
  1660. #line 1457 "ctangle.w"
  1661. {
  1662. char c;
  1663. while(1){
  1664. if(loc>limit&&get_line()==0)return;
  1665. *(limit+1)= '@';
  1666. while(*loc!='@')loc++;
  1667. if(loc++<=limit){
  1668. c= *loc++;
  1669. if(ccode[(eight_bits)c]==new_section)break;
  1670. switch(ccode[(eight_bits)c]){
  1671. case translit_code:/*94:*/
  1672. #line 1483 "ctangle.w"
  1673.  
  1674. while(xisspace(*loc)&&loc<limit)loc++;
  1675. loc+= 3;
  1676. if(loc>limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2))
  1677. ||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1)))
  1678. #line 722 "ctangle.ch"
  1679. err_print(get_string(MSG_ERROR_CT94_1));
  1680. #line 1489 "ctangle.w"
  1681.  
  1682. else{
  1683. unsigned i;
  1684. char*beg;
  1685. sscanf(loc-3,"%x",&i);
  1686. while(xisspace(*loc)&&loc<limit)loc++;
  1687. beg= loc;
  1688. while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||*loc=='_'))loc++;
  1689. if(loc-beg>=translit_length)
  1690. #line 729 "ctangle.ch"
  1691. err_print(get_string(MSG_ERROR_CT94_2));
  1692. #line 1499 "ctangle.w"
  1693.  
  1694. else{
  1695. #line 736 "ctangle.ch"
  1696. strncpy(translit[i-0200],beg,(size_t)(loc-beg));
  1697. #line 1502 "ctangle.w"
  1698. translit[i-0200][loc-beg]= '\0';
  1699. }
  1700. }
  1701.  
  1702. #line 758 "ctangle.ch"
  1703. /*:94*/
  1704. #line 1467 "ctangle.w"
  1705. ;break;
  1706. case format_code:case'@':break;
  1707. case control_text:if(c=='q'||c=='Q'){
  1708. while((c= skip_ahead())=='@');
  1709. if(*(loc-1)!='>')
  1710. #line 708 "ctangle.ch"
  1711. err_print(get_string(MSG_ERROR_CT68_2));
  1712. #line 1473 "ctangle.w"
  1713.  
  1714. break;
  1715. }
  1716. #line 715 "ctangle.ch"
  1717. default:err_print(get_string(MSG_ERROR_CT93));
  1718. #line 1477 "ctangle.w"
  1719.  
  1720. }
  1721. }
  1722. }
  1723. }
  1724.  
  1725. /*:93*//*95:*/
  1726. #line 763 "ctangle.ch"
  1727.  
  1728. void print_stats(void){
  1729. printf(get_string(MSG_STATS_CT95_1));
  1730. printf(get_string(MSG_STATS_CT95_2),
  1731. (long)(name_ptr-name_dir),(long)max_names);
  1732. printf(get_string(MSG_STATS_CT95_3),
  1733. (long)(text_ptr-text_info),(long)max_texts);
  1734. printf(get_string(MSG_STATS_CT95_4),
  1735. (long)(byte_ptr-byte_mem),(long)max_bytes);
  1736. printf(get_string(MSG_STATS_CT95_5),
  1737. (long)(tok_ptr-tok_mem),(long)max_toks);
  1738. }
  1739. #line 1522 "ctangle.w"
  1740.  
  1741. #line 782 "ctangle.ch"
  1742. /*:95*/
  1743.